package dao;

import java.util.List;

import model.Promocoes;

import org.hibernate.Criteria;
import org.hibernate.Session;

import org.hibernate.Transaction;

import util.HibernateUtil;

public class PromocaoDAO {
    public PromocaoDAO() {
        session = HibernateUtil.getSessionFactory().openSession();
    }
    
    private Session session;
    
    public void insert(Promocoes p){
        Transaction t = session.beginTransaction();
        session.merge(p);
        t.commit();
    }
    
    public void delete(Promocoes p){
        Transaction t = session.beginTransaction();
        session.delete(p);
        t.commit();
    }
    
    public List<Promocoes> findAll(){
        Criteria criteria = session.createCriteria(Promocoes.class);
        return criteria.list();
    }
    
    public static void main(String[] args) {
        PromocaoDAO pDAO = new PromocaoDAO();
        for (Promocoes p : pDAO.findAll()){
            System.out.println(p.getTipopromocao_id());
        }
    }
}
